package net.sunzc.base.ui;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import net.sunzc.base.BaseApplication;
import net.sunzc.base.R;
import net.sunzc.base.ui.widget.HeaderView;

/**
 * Created by mac on 15/11/27.
 */
public class BaseTitleActivity extends AppCompatActivity {

    protected HeaderView mTitleBar;
    protected BaseApplication mApplication;
    protected Context mActivityContext, mAppContext;

    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        mApplication = (BaseApplication) getApplication();
        mActivityContext = getBaseContext();
        mAppContext = getApplicationContext();
    }

    @Override
    public void setContentView(int layoutId) {
        setContentView(View.inflate(this, layoutId, null));
    }

    protected HeaderView getTitleBar() {
        return mTitleBar;
    }

    @Override
    public void setContentView(View view) {
        addTitleBar(view);
    }

    private void addTitleBar(View view) {
        RelativeLayout rootLayout = (RelativeLayout) findViewById(R.id.root_layout);
        if (rootLayout == null) {
            return;
        }
        mTitleBar = (HeaderView) findViewById(R.id.title_bar);
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        lp.addRule(RelativeLayout.BELOW, R.id.title_bar);
        view.setLayoutParams(lp);
        rootLayout.addView(view);
    }


}
